package de.tu_darmstadt.gdi1.towerdefense.model.mapmodel;

import java.awt.Point;
import java.util.ArrayList;

public class AMap {

	/**
	 * char[][] Map / The original map
	 */
	private char[][] currentMap;

	/**
	 * the original map as a char[][]
	 */
	private char[][] originalMap;

	//
	// private ParserMap myMap;
	/*
	 * ArrayList<WayPoint> of WayPoints
	 */
	private ArrayList<WayPoint> wayPoint = new ArrayList<WayPoint>();

	/**
	 * The start point as a Point
	 */
	private Point startPoint;

	/**
	 * 
	 * @return Point startPoint
	 */
	public Point getStartPoint() {
		return startPoint;
	}

	/**
	 * 
	 * @return Point goalPoint
	 */
	public Point getGoalPoint() {
		return goalPoint;
	}

	/**
	 * Point goalPoint
	 */
	private Point goalPoint;

	/*
	 * A Map for the game Tower Defense
	 * 
	 * constructor init: currentMap = new char[][] { {} }; originalMap = new
	 * char[][] { {} }; wayPoint = new ArrayList<WayPoint>(); startPoint = new
	 * Point(0, 0); goalPoint = new Point(0, 0);
	 */
	public AMap() {
		currentMap = new char[][] { {} };
		originalMap = new char[][] { {} };
		wayPoint = new ArrayList<WayPoint>();
		startPoint = new Point(0, 0);
		goalPoint = new Point(0, 0);
	}

	/**
	 * set the original map in AMap
	 * 
	 * @param mapFormTowerdefenModel
	 *            char[][]
	 */
	public void setOrginalMap(char[][] mapFormTowerdefenModel) {
		originalMap = new char[mapFormTowerdefenModel.length][mapFormTowerdefenModel[0].length];
		System.arraycopy(mapFormTowerdefenModel, 0, originalMap, 0,
				mapFormTowerdefenModel.length);

		// originalMap = mapFormTowerdefenModel;
	}

	/**
	 * set the wayPoints of a map
	 * 
	 * @param _wayPoint
	 *            ArrayList<WayPoint>
	 */
	public void setWaypoints(ArrayList<WayPoint> _wayPoint) {
		wayPoint = _wayPoint;
	}

	/**
	 * copy the map
	 * 
	 * @param char[][] aLevel
	 */
	public void setMap(char[][] aLevel) {
		currentMap = new char[aLevel.length][aLevel[0].length];
		for (int x = 0; x < aLevel.length; x++)
			for (int y = 0; y < aLevel[0].length; y++) {
				currentMap[x][y] = aLevel[x][y];
			}

	}

	/**
	 * the currentMap
	 * 
	 * @return char[][] currentMap
	 */
	public char[][] getMap() {
		return currentMap;
	}

	/**
	 * return the WayPoints of the current map
	 * 
	 * @return ArrayList<WayPoint> wayPoint
	 */
	public ArrayList<WayPoint> getWaypoint() {
		return wayPoint;
	}

	/**
	 * set the Monster in the current map
	 * 
	 * @param x
	 * @param y
	 */
	public void setMonsterPosition(int x, int y) {
		currentMap[y][x] = 'M';
	}

	/**
	 * remove a Monster from the current Map
	 * 
	 * @param x
	 * @param y
	 */
	public void removeMonsterFromMap(int x, int y) {
		if (currentMap[y][x] == 'M')
			currentMap[y][x] = originalMap[y][x];
	}

	/**
	 * to String method of the current Map
	 * 
	 * @return StringBuffer toString
	 */
	public String printMap() {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < currentMap.length; i++) {
			for (int j = 0; j < currentMap[0].length; j++) {
				sb.append(currentMap[i][j]);
			}
			if (!sb.toString().equals(""))
				sb.append("\n");
		}
		return sb.toString();
	}

	/**
	 * Set the start Point where a monster can start
	 * 
	 * @param point
	 */
	public void setStartPoint(Point point) {
		startPoint = point;
	}

	/**
	 * set the target for the monsters
	 * 
	 * @param point
	 */
	public void setGoalPoint(Point point) {
		goalPoint = point;
	}

	/**
	 * return a map with only the card without monsters and towers
	 * 
	 * @return char[][] Orginal map
	 */
	public char[][] getOriginalMap() {
		return originalMap;
	}

}
